<%--
  User: zhouyanchao
  Date: 2017/11/8
--%>
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>rest示例</title>
</head>
<body>
<button type="button" id="addBtn">添加数据</button>
<button type="button" id="deleteBtn">删除数据</button>
<button type="button" id="updateBtn">修改数据</button>
<button type="button" id="getBtn">获取单条数据</button>
<button type="button" id="getallBtn">获取多条数据</button>

<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>

<script>
	$(function () {
		//添加数据
		$('#addBtn').click(function () {
			$.ajax({
				url:'demo.do',
				type:'post',
				data:{name:'zhang'},
				dataType:'json',
				success:function (result) {
					console.log(result);
				},
				error:function (req,msg,obj) {
					
				}

			});
		});
		//删除数据
		$('#deleteBtn').click(function () {
			$.ajax({
				url:'demo/1.do',
				type:'post',
				data:{
					_method:'delete'
				},
				dataType:'json',
				success:function (result) {
					console.log(result);
				},
				error:function (req,msg,obj) {
					console.log(msg);
				}

			});
		});
		$('#updateBtn').click(function () {
			$.ajax({
				url:'demo/1.do',
				type:'post',
				data:{
					name:'zhang修改的',
					_method:'put'
				},
				dataType:'json',
				success:function (result) {
					console.log(result);
				},
				error:function (req,msg,obj) {

				}

			});
		});
		//查单条
		$('#getBtn').click(function () {
			$.ajax({
				url:'demo/1.do',
				type:'get',
				dataType:'json',
				success:function (result) {
					console.log(result);
				},
				error:function (req,msg,obj) {

				}

			});
		});
		//查所有
		$('#getallBtn').click(function () {
			$.ajax({
				url:'demos.do',
				type:'get',
				dataType:'json',
				success:function (result) {
					console.log(result);
				},
				error:function (req,msg,obj) {

				}

			});
		});
	});

</script>


</body>
</html>
